"use strict";
cc._RF.push(module, '9d45dhe6RdASIacuGGU7Ss9', 'LotteryManager');
// scripts/LotteryManager.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("GlobalUserData"),
    s = t("HallCarTotalView"),
    l = t("HallConstant"),
    c = t("HallScene"),
    d = t("BroadCastMessage"),
    h = t("NativeManager"),
    p = t("Util"),
    u = t("ChampionManager"),
    f = t("LotteryElement"),
    m = t("NumberAction"),
    _ = t("Global"),
    y = t("RedPointControl "),
    g = t("BaseStorage"),
    v = t("StorageManager"),
    C = cc._decorator,
    b = C.ccclass,
    w = C.property,
    S = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.videoNode = null, e.btn = null, e.bonusArr = [], e.loopCount = 5, e.curBonus = null, e.btnClose = null, e.btnLottery = null, e.btnShowAd = null, e.label = null, e.label_tip = null, e.pro_luckValue = null, e.label_pro = null, e.officialsHint = null, e.luckyLvl = null, e.btnluckyLvl = null, e.index = 0, e.freeNum = 0, e;
  }

  return n(e, t), e.prototype.onLoad = function () {
    this.videoNode.active = !1, v.StorageManager.setDailyTaskStorageKey(_.BaseStorageKey.LotteryCount, _.BaseStorageKey.GetLotteryNumber), g.BaseStorage.getInt(_.BaseStorageKey.LuckyCar, 0) ? this.officialsHint.string = "幸运值为100%时，必中1000钻石" : this.officialsHint.string = "幸运值为100%时，必中战车";

    for (var t = 0; t < this.bonusArr.length; t++) {
      this.bonusArr[t].init(this);
    }

    var e = new Date().getDay();
    this.freeNum = 0 == e || 6 == e ? 3 + u["default"].Ins.getGradeBuff(r["default"].nTrophy, null).lottery : 1;
  }, e.prototype.start = function () {
    var t = this;
    this.btnLottery.x = 0, this.btnShowAd.active = !1;
    var e = r["default"].nTotalGame % 6;
    p.Util.is_qg() && !r["default"].bAuditMode && r["default"].nativeMistakeBannerList[e] && p.Util.showNativeBanner(2, this.btnShowAd, function () {
      t.btnLottery.x = 120, t.btnClose.active = !1, setTimeout(function () {
        t.btnClose.active = !0;
      }, 2e3), p.Util.hideBanner();
    }), p.Util.hideHallBanner(), this.label.active = !1, this.refreshLotteryStatus(), p.Util.hideSingleCustomAd(), p.Util.showRightSingleCustomAd(), y.RedPointControl.getInstance().cal(_.RedPointCalKey.Lottery);
  }, e.prototype.onClickNativeBanner = function () {
    p.Util.clickNativeBanner(2);
  }, e.prototype.onEnable = function () {
    this.curBonus && (this.curBonus.IsSelected = !1), p.Util.is_233() && h["default"].instance.showFullVideoAd();
  }, e.prototype.refreshLotteryStatus = function () {
    var t = 10 - g.BaseStorage.getInt(_.BaseStorageKey.LotteryCount, 0),
        e = this.freeNum - g.BaseStorage.getInt(_.BaseStorageKey.LotteryCount, 0);
    e = e < 0 ? 0 : e, this.label_tip.string = "今日剩余抽奖次数" + t + "次（免费" + e + "次）";
    var o = g.BaseStorage.getInt(_.BaseStorageKey.Lucky, 0) / 100 > 1 ? 1 : g.BaseStorage.getInt(_.BaseStorageKey.Lucky, 0) / 100;
    this.pro_luckValue.progress = o < 0 ? 0 : o, this.label_pro.string = Math.floor(100 * o) + "%", this.count = this.bonusArr.length, e <= 0 && (this.videoNode.active = !0, p.Util.videoExposure(_.VideoTab.dim14)), this.btnluckyLvl.spriteFrame = this.videoNode.active ? this.luckyLvl : this.btnluckyLvl.spriteFrame, g.BaseStorage.getInt(_.BaseStorageKey.LotteryCount, 0) >= 10 ? (this.btnShowAd.active = !1, this.label.active = !0, this.btn.node.active = !1) : this.btn.interactable = !0;
  }, e.prototype.launch = function () {
    d["default"].getInstance().SendMessage(l.Broadcast_Func.Audio, l.Audio_ID.btn_click), this.videoNode.active ? p.Util.showRewardVideo(this.getGift.bind(this), null, null, !1) : this.getGift();
  }, e.prototype.getGift = function () {
    var t = 0;
    if (g.BaseStorage.getInt(_.BaseStorageKey.Lucky, 0) + this.getLuckAdd() >= 100) this.index = 9, this.luck(this.index);else for (var e = 0; e < this.bonusArr.length; e++) {
      if (t += this.bonusArr[e].getProbability(), p.Util.probability(t)) {
        this.index = e, this.luck(e);
        break;
      }
    }
  }, e.prototype.luck = function (t) {
    this.run_animation_get_reward(t, this.getAward.bind(this)), this.btn.interactable = !1;
  }, e.prototype.getAward = function () {
    var t = this;
    this.scheduleOnce(function () {
      t.bonusArr[t.index].getGift();
      var e = g.BaseStorage.getInt(_.BaseStorageKey.LotteryCount, 0) + 1;
      g.BaseStorage.setInt(_.BaseStorageKey.LotteryCount, e);
      var o = g.BaseStorage.getInt(_.BaseStorageKey.Lucky, 0) + t.getLuckAdd();
      o >= 100 && (o = 0), g.BaseStorage.setInt(_.BaseStorageKey.Lucky, o), t.refreshLotteryStatus();
    }, .4);
  }, e.prototype.getLuckAdd = function () {
    return 10;
  }, e.prototype.run_animation_get_reward = function (t, e) {
    var o = this,
        i = new m.NumberAction(this.count * this.loopCount + t, 0, .05, this, function (t) {
      o.bonusLoop(Math.floor(t) % o.count);
    }, e);
    i.easeing = m.EASING.INVERSE_PROPORTIONAL, m.runNumberActions([i], 3);
  }, e.prototype.bonusLoop = function (t) {
    this.curBonus && (this.curBonus.IsSelected = !1), this.curBonus = this.bonusArr[t], this.curBonus.IsSelected = !0;
  }, e.prototype.backHall = function () {
    g.BaseStorage.setInt(_.BaseStorageKey.LuckyCar, 1), cc.find("Canvas").getChildByName("car").getComponent(s["default"]).setFreeCar(), cc.find("Canvas").getComponent(c["default"]).refreshNewCommer(), this.close();
  }, e.prototype.getDateString = function () {
    return new Date().toDateString();
  }, e.prototype.close = function () {
    d["default"].getInstance().SendMessage(l.Broadcast_Func.Audio, l.Audio_ID.btn_click), this.node.destroy(), p.Util.hideBanner(), p.Util.showSingleCustomAd(), p.Util.hideLeftSingleCustomAd(), p.Util.hideRightSingleCustomAd(), y.RedPointControl.getInstance().cal(_.RedPointCalKey.Lottery), p.Util.hideNativeBanner(), p.Util.showHallBanner();
  }, a([w(cc.Node)], e.prototype, "videoNode", void 0), a([w(cc.Button)], e.prototype, "btn", void 0), a([w(f["default"])], e.prototype, "bonusArr", void 0), a([w(cc.Float)], e.prototype, "loopCount", void 0), a([w(cc.Node)], e.prototype, "btnClose", void 0), a([w(cc.Node)], e.prototype, "btnLottery", void 0), a([w(cc.Node)], e.prototype, "btnShowAd", void 0), a([w(cc.Node)], e.prototype, "label", void 0), a([w(cc.Label)], e.prototype, "label_tip", void 0), a([w(cc.ProgressBar)], e.prototype, "pro_luckValue", void 0), a([w(cc.Label)], e.prototype, "label_pro", void 0), a([w(cc.Label)], e.prototype, "officialsHint", void 0), a([w(cc.SpriteFrame)], e.prototype, "luckyLvl", void 0), a([w(cc.Sprite)], e.prototype, "btnluckyLvl", void 0), a([b], e);
}(cc.Component);

o["default"] = S;

cc._RF.pop();